const timeslots = ["00:00 ~ 03:00", "03:00 ~ 06:00", "06:00 ~ 08:00", "08:00 ~ 09:00", "09:00 ~ 10:00", "10:00 ~ 11:00", "11:00 ~ 12:00", "12:00 ~ 13:00", "13:00 ~ 14:00", "14:00 ~ 15:00", "15:00 ~ 16:00", "16:00 ~ 17:00", "16:00 ~ 17:00", "17:00 ~ 18:00", "18:00 ~ 21:00", "21:00 ~ 24:00"]

function getCurrentTimeSlot() {
  const hour = new Date().getHours()

  return timeslots.find(item => {
    const [hour_0, hour_1] = item.split(' ~ ').map(m => m.split(':')[0]);
    return +hour >= +hour_0 && +hour < hour_1;
  })
}

function getSlot(value) {
  if (!value) {
    return {
      date: '',
      timeSlotCode: ''
    }
  }
  const date = value.substr(0, 10);
  const timeslot = value.substr(11);

  return {
    date,
    timeSlotCode: timeslots.indexOf(timeslot) + 1
  }
}

getSlot.getCurrentTimeSlot = getCurrentTimeSlot

module.exports = getSlot